<script>
init({
  title: 'Reorder Columns',
  desc: 'Use Plugin: <a href="https://github.com/akottr/dragtable/" target="_blank">dragtable</a> and bootstrap-table-reorder-columns.',
  links: [
    'https://cdn.jsdelivr.net/gh/akottr/dragtable@master/dragtable.css',
    'bootstrap-table.min.css'
  ],
  scripts: [
    'https://cdn.jsdelivr.net/npm/jqueryui@1.11.1/jquery-ui.min.js',
    'https://cdn.jsdelivr.net/gh/akottr/dragtable@master/jquery.dragtable.js',
    'bootstrap-table.min.js',
    'extensions/reorder-columns/bootstrap-table-reorder-columns.min.js'
  ]
})
</script>

<template>
  <div class="toolbar">
    <button
      id="order1"
      class="btn btn-primary"
    >
      Order by Name, ID, price
    </button>
    <button
      id="order2"
      class="btn btn-primary"
    >
      Order by Price, Name, ID
    </button>
  </div>

  <table
    id="table"
    data-toolbar=".toolbar"
    data-show-columns="true"
    data-search="true"
    data-show-toggle="true"
    data-pagination="true"
    data-url="json/data1.json"
    data-reorderable-columns="true"
  >
    <thead>
      <tr>
        <th
          data-field="id"
          data-sortable="true"
        >
          ID
        </th>
        <th
          data-field="name"
          data-sortable="true"
        >
          Item Name
        </th>
        <th
          data-field="price"
          data-sortable="true"
        >
          Item Price
        </th>
      </tr>
    </thead>
  </table>
</template>

<script>
  function mounted () {
    $('#table').bootstrapTable()

    $('#order1').on('click', () => {
      $('#table').bootstrapTable('orderColumns', {
        name: 0,
        id: 1,
        price: 2
      })
    })

    $('#order2').on('click', () => {
      $('#table').bootstrapTable('orderColumns', {
        price: 0,
        name: 1,
        id: 2
      })
    })
  }
</script>
